package com.example.config.security;

import java.util.ArrayList;
import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

@Order(Ordered.HIGHEST_PRECEDENCE)
@Configuration
public class AuthenticationSecurity {

	@Autowired
	private PasswordEncoder passwordEncoder;
	
	@Bean
	public InMemoryUserDetailsManager inMemoryUserDetailsManager() {
		Collection<UserDetails> users = new ArrayList<>();
		users.add(User
				.withUsername("admin")
				.password(passwordEncoder.encode("password"))
				.roles("ADMIN", "USER")
				.authorities("ADMIN", "ROLE_ACTUATOR")
				.build());
		users.add(User
				.withUsername("user")
				.password(passwordEncoder.encode("password"))
				.roles("USER")
				.authorities("USER")
				.build());
		return new InMemoryUserDetailsManager(users);
	}
	
	
}